local extension = Package:new("huixiang1")
extension.extensionName = "b-huixiang"

Fk:loadTranslationTable{
  ["huixiang1"] = "乙巳回想",
  ["fhlt"] = "烽火连天",
  ["sy"] = "2022三英改",
  ["yi"] = "忆",
  ["hxgod"] = "神临doro",
}

--[[
local doro_prohibit= fk.CreateTriggerSkill{
  name = "#doro_prohitbit",
  events = {fk.AfterSkillEffect,fk.AfterCardsMove},
  priority = 0.1,
  global = true,
  mute = true,
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    local can = 0
    for _, p in ipairs(room.alive_players) do
      if not p.dead and (string.find(p.general, "huixiangqy__jiecaoang") or string.find(p.general, "huixiangqy__mouguojia")
      or string.find(p.general, "huixiangqy__mousimayi") or string.find(p.general, "huixiangqy__mouxuchu")
      or string.find(p.general, "huixiangqy__moudianwei") or string.find(p.general, "huixiangqy__moucaochong"))
      or string.find(p.general, "huixiangqy__xingcaochun") or string.find(p.general, "huixiangqy__spzhugeliang")
      or string.find(p.general, "huixiangqy__jiemaliang") or string.find(p.general, "huixiangqy__moumadai")
      or string.find(p.general, "huixiangqy__jietaishici") or string.find(p.general, "huixiangqy__spzhouyu")
      or string.find(p.general, "huixiangqy__shisunquan") or string.find(p.general, "huixiangqy__mouganning")
      or string.find(p.general, "huixiangqy__daoxusheng") or string.find(p.general, "huixiangqy__spsimayi")
      or string.find(p.general, "huixiangqy__xingliubei") or string.find(p.general, "huixiangqy__shimachao")
      or string.find(p.general, "huixiangqy__jiequyi") or string.find(p.general, "huixiangqy__maoliuyan")
      or string.find(p.general, "huixiangqy__hewenyang") or string.find(p.general, "huixiangqy__nujvshou")
      or string.find(p.general, "huixiangqy__bianzhouchu") or string.find(p.general, "huixiangqy__xingzuoci")
      or string.find(p.general, "huixiangqy__shenxusheng") or string.find(p.general, "yi__simayi")
      or string.find(p.general, "hxqunyou__chgs") or string.find(p.general, "hxqunyou__jimiheng")
      or string.find(p.general, "hxqunyou__qiamimiao") or string.find(p.general, "hxqunyou__guinv")
      or string.find(p.general, "hxqunyou__songxingnu") or string.find(p.general, "hxqunyou__wuming")
      or string.find(p.general, "hxqunyou__ytys") or string.find(p.general, "hxqunyou__dabai")
      or string.find(p.general, "hxqunyou__genie") or string.find(p.general, "hxqunyou__limulu")
      or string.find(p.general, "hxqunyou__ronghuanggai") or string.find(p.general, "hxqunyou__nijvshou")
      or string.find(p.general, "hxqunyou__fkyshr") or string.find(p.general, "hxqunyou__muzhugeliang")
      or string.find(p.general, "hxqunyou__ruifeng") or string.find(p.general, "hxqunyou__xingsunce")
      or string.find(p.general, "hxqunyou__T800") or string.find(p.general, "hxqunyou__yanchixia")
      then
        can = can + 1
      end
    end
    if can == 0 then return false end
    if event == fk.AfterSkillEffect then
     return target == player and target and player:hasSkill(data) and data.name ~= self.name and
     (player:usedSkillTimes(data.name, Player.HistoryTurn) >= 20 or player:usedSkillTimes(data.name, Player.HistoryPhase) >= 20)
    elseif event == fk.AfterCardsMove then
      local num = 0
      room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
      for _, move in ipairs(e.data) do
        if (move.toArea == Card.PlayerHand or move.toArea == Card.PlayerEquip) and move.to and move.to == player.id and move.moveReason == fk.ReasonDraw then
          for _, info in ipairs(move.moveInfo) do
            num = num + 1
          end
        end
      end
      end, Player.HistoryTurn)
      return num > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterSkillEffect then
      room:doBroadcastNotify("ShowToast", "doro在注视着你~~~")
      room:doBroadcastNotify("ShowToast", "你已受到神doro的注视，鉴于你发动技能太多的行为，神doro决定中止一切结算！")
      room.logic:getCurrentEvent():findParent(GameEvent.Phase):shutdown()
    elseif event == fk.AfterCardsMove  then
      if player.dead then return false end
      room:addPlayerMark(player, "doro_zhushi-turn", 1)
      if player:getMark("doro_zhushi-turn") >= 18 then
        room:doBroadcastNotify("ShowToast", "doro在注视着你~~~")
      end
      if player:getMark("doro_zhushi-turn") >= 20 then
        room:doBroadcastNotify("ShowToast", "你已受到神doro的注视，鉴于你摸牌次数太多的行为，神doro决定中止一切结算！")
        room.logic:getCurrentEvent():findParent(GameEvent.Phase):shutdown()
      end
    end
  end,
}

Fk:addSkill(doro_prohibit)

--]]




local hxqunyou__erweima = General:new(extension, "hxqunyou__erweima","qun",32,47)
Fk:loadTranslationTable{
  ["hxqunyou__erweima"] = "投稿二维码",
  ["#hxqunyou__erweima"] = "征集到跑路为止",
  ["hx__nagao"] = "纳稿",
  [":hx__nagao"] = "锁定技，你成为其他角色使用牌的目标时，令此牌对你无效然后你失去1点体力。"..
  "<br/>任意题材，将根据技能的有趣程度和难易程度选择性采纳。除去这些，首个武将不是很💩的也会择日实现。你的武将一个没写就是不行，可以多投几个。（tips:可从技能联动性、对牌的利用性等方面出发）",
}

local hx__nagao = fk.CreateTriggerSkill{
  name = "hx__nagao",
  events = { fk.TargetConfirming},
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.TargetConfirming then
        return data.from and data.from ~= player.id and target == player and data.card.is_damage_card
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirming then
      room:doIndicate(player.id, { data.from })
      AimGroup:cancelTarget(data, player.id)
      room:loseHp(player, 1,self.name)
    end
  end,
}
hxqunyou__erweima:addSkill(hx__nagao)



local lvbu = General:new(extension, "sy__lvbu","qun",10)

local baguan2022buff = fk.CreateTriggerSkill{
  name = "#baguan2022buff",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.DrawNCards},
  on_use = function(self,event,target,player,data)
    player:broadcastSkillInvoke("baguan2022")
    data.n = data.n + 3
  end,
}

local baguan2022 = fk.CreateTriggerSkill{
  name = "baguan2022",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.BeforeTurnOver, fk.EventPhaseSkipping},
  on_use = function(self, event, target, player, data)
      return true
  end,
}

local wuwei2022buff = fk.CreateTargetModSkill{
  name = "#wuwei2022buff",
  residue_func = function(self, player, skill, scope)
    if player:hasSkill(self) and skill.trueName == "slash_skill"
      and scope == Player.HistoryPhase then
      return 2
    end
  end,
}

local lvbuwuwei2022 = fk.CreateTriggerSkill{
name = "lvbuwuwei2022",
anim_type = "offensive",
events = {fk.AfterCardTargetDeclared},
can_trigger = function(self, event, target, player, data)
  return target == player and player:hasSkill(self) and not player.dead and
    (data.card.trueName == "duel" or data.card.trueName == "slash") and #player.room:getUseExtraTargets(data) > 0
end,
on_use = function (self, event, target, player, data)
    local targets = player.room:getUseExtraTargets(data)
    local tos = player.room:askForChoosePlayers(player, targets, 1, 2,
      "#lvbuwuwei2022-choose:::"..data.card:toLogString(), "lvbuwuwei2022", true)
    if #tos > 0 then
      table.forEach(tos, function (id)
        table.insert(data.tos, {id})
      end)
    end
end,
}

local jinghu2022 = fk.CreateTriggerSkill{
  name = "jinghu2022",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = { fk.Damage },
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      return data.to~=player and not data.to.dead
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damage then
     room:loseHp(data.to, 1)
    end
  end,
}
 
local jianju2022buff = fk.CreateDistanceSkill{
  name = "#jianju2022buff",
  frequency = Skill.Compulsory,
  correct_func = function(self, from, to)
    if from:hasSkill(self) then
      return -999
    end
  end,
}

local jianju2022 = fk.CreateTriggerSkill{
  name = "jianju2022",
  events = { fk.Deathed, fk.RoundEnd,fk.TurnEnd },
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.TurnEnd then
    return target == player and player:hasSkill(self) and player.room:getTag("RoundCount") == 3 
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if not player.dead then
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if not p.dead then
          room:killPlayer({who = player.id})
          room:killPlayer({ who = p.id })
        end
      end
    end
  end,
}

local kaiju2022 = fk.CreateTriggerSkill{
  name = "kaiju2022",
  events = {fk.RoundStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player.room:getTag("RoundCount") == 1
  end,
  on_use = function(self, event, target, player, data)
    player:gainAnExtraTurn()
  end,
 }
lvbu:addSkill(kaiju2022)
lvbu:addSkill(baguan2022)
baguan2022:addRelatedSkill(baguan2022buff)
lvbu:addSkill(lvbuwuwei2022)
lvbuwuwei2022:addRelatedSkill(wuwei2022buff)
lvbu:addSkill(jinghu2022)
lvbu:addSkill(jianju2022)
jianju2022:addRelatedSkill(jianju2022buff)



Fk:loadTranslationTable{
  ["baguan2022"] = "霸关",
  ["#baguan2022buff"] = "霸关",
  [":baguan2022"] = "锁定技，你的阶段不能被跳过，你不会被翻面。你的摸牌阶段额外摸3张牌。", 
  ["$baguan20221"] = "哼，你是赢不了的",
  ["$baguan20222"] = "哼，你自以为，能战胜我？",
}

Fk:loadTranslationTable{
    ["sy__lvbu"] = "吕布",
    ["#sy__lvbu"] = "神威再临",
    ["designer:sy__lvbu"] = "庆思书",
    ["lvbuwuwei2022"] = "武威",
    [":lvbuwuwei2022"] = "你使用【杀】或【决斗】可以额外指定两个目标。你的出牌阶段可以多使用两张【杀】。",
    ["#lvbuwuwei2022-choose"] = "武威：你可以为%arg增加至多两个目标",
    ["jinghu2022"] = "惊虎",
    [":jinghu2022"] = "锁定技，你对一名其他角色造成伤害后令其失去1点体力。",
    ["jianju2022"] = "健驹",
    [":jianju2022"] = "锁定技，你与其他角色的距离视为1。第三轮你的回合结束后，令所有角色依次死亡。",
    ["kaiju2022"] = "再临",
    [":kaiju2022"] = "锁定技，首轮开始时，你执行额外的回合。",
    ["$lvbuwuwei20221"] = "到我了！马上，你就要为所做的一切付出代价！",
    ["$lvbuwuwei20222"] = "乱世英雄，舍我其谁！",
    ["$jinghu20221"] = "一切，才刚刚开始。",
    ["$jinghu20222"] = "休要言他，受死吧！",
    ["$jianju2022"] = "退退退，且行罢兵，来日再战",
    ["$kaiju2022"] = "（三英联军与战神吕布的开战对话）",
    ["~sy__lvbu"] = "是吕布败了，关我奉先什么事？",
  }

local chenxiang = General:new(extension, "fhlt__chenxiang","god",3)

--会心
local huixin = fk.CreateTriggerSkill{
  name = "huixiang_huixin",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and target == player
  end,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage * 2
  end,
}
Fk:loadTranslationTable{
  ["huixiang_huixin"] = "会心",
  [":huixiang_huixin"] = "锁定技，你造成的伤害翻倍。",
}

-- 闭户
local bihu = fk.CreateTriggerSkill{
  name = "huixiang_bihu",
  anim_type = "defensive",
  events = {fk.TargetConfirming},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.TargetConfirming then
      if target == player and player:hasSkill(self) and data.card.is_damage_card and (data.card.trueName == "slash" or data.card.type == Card.TypeTrick) then
        -- 检查本回合是否获得过牌
        local hasGained = false
        player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
          for _, move in ipairs(e.data) do
            if move.to == player.id and (move.toArea == Card.PlayerHand or move.toArea == Card.PlayerEquip) then
              hasGained = true
              return true 
            end
          end
        end, Player.HistoryTurn)
        return not hasGained
      end
    end
    return false
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirming then
      AimGroup:cancelTarget(data, player.id)
    end
  end,
}
Fk:loadTranslationTable{
  ["huixiang_bihu"] = "闭户",
  [":huixiang_bihu"] = "锁定技，当你成为【杀】或其他伤害类锦囊牌的目标时，若本回合你没有获得过牌，取消之。",
  
}

-- 远避
local yuanbi = fk.CreateTriggerSkill{
  name = "huixiang_yuanyi",
  anim_type = "negative",
  events = { fk.DamageInflicted },
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.from then
      return data.damage > 0 and data.from:getAttackRange() < 4
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.from:getAttackRange() < 4 then
      data.damage = 0
      room:loseHp(player, 1,self.name)
      player:broadcastSkillInvoke(self.name, 1)
      room:notifySkillInvoked(player, self.name, "defensive")
    end
  end,
}
Fk:loadTranslationTable{
  ["huixiang_yuanyi"] = "远避",
  [":huixiang_yuanyi"] = "锁定技，当你受到伤害时，若伤害来源攻击范围小于4，防止此伤害改为失去一点体力。",
}

local huixinag__fenghuo = fk.CreateTriggerSkill{
  name = "huixiang__fenghuo",
  events = {fk.EventPhaseStart},
  prompt = "#huixiang__fenghuo",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start and  player:usedSkillTimes(self.name, Player.HistoryGame) < 1
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#huixiang__fenghuo")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    -- 失去一个技能
    local skills = table.map(table.filter(player.player_skills, function (s)
      return s.visible and not (s:isEquipmentSkill(player) or s.name:endsWith("&") or s.name == self.name)
    end), Util.NameMapper)
      local choice = room:askForChoice(player, skills, self.name, "#huixiang__fenghuo-lose-choose", true)
      room:handleAddLoseSkills(player, skills, nil, true)
      player.room:handleAddLoseSkills(player, "-"..choice)
    -- 获得技能
    local generals = table.filter(room.general_pile, function (general_name)
      local general = Fk.generals[general_name]
      return true
    end)
    if #generals > 0 then
      generals = table.random(generals, 5)
      local general = Fk.generals[room:askForGeneral(player, generals, 1, true)]
      local skills = general:getSkillNameList()
      room:handleAddLoseSkills(player, table.concat(skills, "|"), nil, false)
    end
  end,
}
chenxiang:addSkill(huixinag__fenghuo)
chenxiang:addSkill(bihu)



Fk:loadTranslationTable{
  ["fhlt__chenxiang"] = "陈香",
  ["#fhlt__chenxiang"] = "梦入轮回",
  ["designer:fhlt__chenxiang"] = "庆思书",
  ["huixiang__fenghuo"] = "烽火",
  [":huixiang__fenghuo"] = "每局限一次，你的准备阶段开始时，你可以选择失去一个技能然后从五张未登场的武将牌中选择一个获得其所有技能。",
  ["#huixiang__fenghuo"] = "烽火：是否要失去一个技能然后从五张未登场的武将牌中选择一个获得其所有技能？",
  ["#huixiang__fenghuo-lose-choose"] = "烽火：请选择要失去的技能",
  ["$huixiang__fenghuo1"] = "匹夫安敢妄议逝者功过，感受这乱世地狱吧！",
  ["$huixiang__fenghuo2"] = "狼烟烽火，永世不灭！",
  ["~fhlt__chenxiang"] = "陈香梦入烽火连天的世界，附身反派首领，无奈为醒梦而战……",
}


local huixiang1__yuzhongbro = General:new(extension, "huixiang1__yuzhongbro", "god", 2,3)

Fk:loadTranslationTable{
  ["huixiang1__yuzhongbro"] = "宇宙兄弟",
  ["#huixiang1__yuzhongbro"] = "兄弟齐心",
  ["designer:huixiang1__yuzhongbro"] = "庆思书",
  ["hx__qifu_bro"] = "齐辅",
  ["#hx__qifu_bro_delay"] = "齐辅",
  [":hx__qifu_bro"] = "锁定技，游戏开始时，你选择一名其他角色，当其受到伤害后，你视为受到等量的伤害；当其回复体力后，你回复等量的体力。",
  ["hx__qice_bro"] = "齐策",
  [":hx__qice_bro"] = "当你受到一点伤害后，你可以进行判定，然后可以弃置一名角色区域里的1张牌或与一名角色各摸1张牌（齐辅的角色多摸一张）。",
  ["hx__rendu_bro"] = "人妒",
  [":hx__rendu_bro"] = "一名角色的判定牌生效后，你可以令你或齐辅的角色获得之。",
  ["hx__nijing_bro"] = "逆境",
  ["#hx__nijing_bro_jiayi"] = "逆境",
  [":hx__nijing_bro"] = "锁定技，你的手牌上限+3；当你进入濒死状态时或你的濒死结算结束后，你摸1张牌；其他角色求桃结束时，你获得1点兄弟之力并令齐辅的角色加一点体力上限并回满体力。",
  ["hx__xinhun_bro"] = "心魂",
  ["#hx__xinhun_bro_delay"] = "心魂",
  [":hx__xinhun_bro"] = "你可以将至多两张你的同花色的牌按以下规则使用或打出：红桃当【桃】，方块当火【杀】，梅花当【闪】，黑桃当【无懈可击】。"..
  "若你以此法使用或打出了两张：红色牌，此牌回复伤害基数+1，且你摸1张牌；黑色牌，你获得当前回合角色区域内1张牌。",
  ["@hx__qifu_bro"] = "齐辅",
  ["#hx__qifu_bro-choose"] = "齐辅: 请选择要齐辅的角色",
  ["#SkillDelayInvoked"] = "%from 的“%arg”的延迟效果被触发",
  ["#hx__qice_bro-discard"] = "齐策：弃置一名角色区域里的1张牌（齐辅的角色死亡时数字加一）",
  ["#hx__qice_bro-draw"] = "齐策：与一名角色各摸1张牌（齐辅的角色多摸一张，且齐辅的角色死亡时数字加一）",
  ["@huixiang1__yuzhongbro"] = "兄弟之力",
  ["@[:]huixiang1__yuzhongbro-intro"] = "兄弟之力",
  ["huixiang1__yuzhongbro-intro"] = "介绍",
  [":huixiang1__yuzhongbro-intro"] = "宇宙兄弟每拥有1点兄弟之力，他武将牌上的技能的阿拉伯数字就+1。",
  ["$hx__xinhun_bro1"] = "龙诞新岁，普天同庆，魂佑宇内，裔泽炎黄。",
  ["$hx__xinhun_bro2"] = "龙吐息而万物生，今龙临神州，华夏当兴！",
  ["$hx__nijing_bro1"] = "龙翔九天，曳日月于天地，换旧符于新岁!",
  ["$hx__nijing_bro2"] = "御风万里，辟邪祟于宇外，映祥瑞于神州!",
  ["$hx__rendu_bro1"] = "随遇而安，闲适自得。",
  ["$hx__rendu_bro2"] = "心境恬适，尽其在我。",
}


local updataXianfu = function (room, player, target)
  local mark = player:getTableMark("hx__qifu_bro")
  table.insertIfNeed(mark[2], target.id)
  room:setPlayerMark(player, "hx__qifu_bro", mark)
  local names = table.map(mark[2], function(pid) return Fk:translate(room:getPlayerById(pid).general) end)
  room:setPlayerMark(player, "@hx__qifu_bro", table.concat(names, ","))
end

local hx__qifu_bro = fk.CreateTriggerSkill{
  name = "hx__qifu_bro",
  priority = 0.1,
  events = {fk.GameStart},
  frequency = Skill.Compulsory,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setBanner("@[:]huixiang1__yuzhongbro-intro","huixiang1__yuzhongbro-intro")
    room:notifySkillInvoked(player, self.name)
    player:broadcastSkillInvoke(self.name, math.random(2))
    local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player,false), Util.IdMapper), 1, 1, "#hx__qifu_bro-choose", self.name, false, true)
    local mark = player:getTableMark(self.name)
    if #mark == 0 then mark = {{},{}} end
    table.insertIfNeed(mark[1], tos[1])
    room:setPlayerMark(player, self.name, mark)
  end,
}
local hx__qifu_bro_delay = fk.CreateTriggerSkill{
  name = "#hx__qifu_bro_delay",
  events = {fk.Damaged, fk.HpRecover},
  frequency = Skill.Compulsory,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    local mark = player:getTableMark("hx__qifu_bro")
    if not player.dead and not target.dead and #mark > 0 and table.contains(mark[1], target.id) then
      return event == fk.Damaged or player:isWounded()
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    updataXianfu (room, player, target)
    room:sendLog{ type = "#SkillDelayInvoked", from = player.id, arg = "hx__qifu_bro", }
    if event == fk.Damaged then
      player:broadcastSkillInvoke("hx__qifu_bro", math.random(2)+2)
      room:damage{
        to = player,
        damage = data.damage,
        skillName = "hx__qifu_bro",
        isVirtualDMG = true,
      }
    else
      player:broadcastSkillInvoke("hx__qifu_bro", math.random(2)+4)
      if player:isWounded() then
        room:recover{
          who = player,
          num = data.num,
          recoverBy = player,
          skillName = "hx__qifu_bro",
        }
      end
    end
  end,
}

local hx__qice_bro = fk.CreateTriggerSkill{
  name = "hx__qice_bro",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for i = 1, data.damage do
      if i > 1 and (self.cancel_cost or not player:hasSkill(self)) then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, data) then
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|^nosuit",
    }
    room:judge(judge)
    if player.dead then return false end
    local choice = room:askForChoice(player, {"Cancel","弃置一名角色的牌", "与一名角色摸牌"}, self.name)
    if choice == "与一名角色摸牌" then
      local targets = table.map(room.alive_players, Util.IdMapper)
      local tos = room:askForChoosePlayers(player, targets, 1, 1, "#hx__qice_bro-draw", self.name, false)
      local to = room:getPlayerById(tos[1])
      local num = 1 + player:getMark("@huixiang1__yuzhongbro")
      player:drawCards(num, self.name)
      local mark = player:getTableMark("hx__qifu_bro")
      if #mark > 0 and table.contains(mark[1], to.id) then
        num = 2 + player:getMark("@huixiang1__yuzhongbro")
        updataXianfu (room, player, to)
      end
      to:drawCards(num, self.name)
    elseif choice == "弃置一名角色的牌" then
      local targets = table.map(table.filter(room.alive_players, function(p) return not p:isAllNude() end), Util.IdMapper)
      if #targets == 0 then return end
      local tos = room:askForChoosePlayers(player, targets, 1, 1, "#hx__qice_bro-discard", self.name, false)
      local to = room:getPlayerById(tos[1])
      local card = room:askForCardChosen(player, to, "hej", self.name)
      room:throwCard({card}, self.name, to, player)
      if player:getMark("@huixiang1__yuzhongbro") > 0 then
        for _ = 1, player:getMark("@huixiang1__yuzhongbro") do
          if not to:isAllNude() then
            local card2 = room:askForCardChosen(player, to, "hej", self.name)
            room:throwCard({card2}, self.name, to, player)
          end
        end
      end
    end
  end,
}

local hx__rendu_bro = fk.CreateTriggerSkill{
  name = "hx__rendu_bro",
  anim_type = "drawcard",
  events = {fk.FinishJudge},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player.room:getCardArea(data.card) == Card.Processing
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askForChoice(player, {"你获得判定牌", "齐辅的角色获得判定牌"}, self.name)
    if choice == "你获得判定牌" then
      room:obtainCard(player.id, data.card, true, fk.ReasonJustMove)
    else
      local mark = player:getTableMark("hx__qifu_bro")
      if #mark == 0 then return end
      local to = room:getPlayerById(mark[1][1])
      if to.dead then return end
      room:obtainCard(to.id, data.card, true, fk.ReasonJustMove)
    end
  end,
}

local hx__nijing_bro = fk.CreateTriggerSkill{
  name = "hx__nijing_bro",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.EnterDying, fk.AfterDying},
  on_use = function(self, event, target, player, data)
    player:drawCards(1 + player:getMark("@huixiang1__yuzhongbro"), self.name)
  end,
}
local hx__nijing_bro_maxcards = fk.CreateMaxCardsSkill{
  name = "#hx__nijing_bro_maxcards",
  correct_func = function(self, player)
    if player:hasSkill(hx__nijing_bro) then
      return 3 + player:getMark("@huixiang1__yuzhongbro")
    end
  end
}

local hx__nijing_bro_jiayi = fk.CreateTriggerSkill{
  name = "#hx__nijing_bro_jiayi",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.AskForPeachesDone},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark("hx__qifu_bro")
    room:addPlayerMark(player, "@huixiang1__yuzhongbro", 1 + player:getMark("@huixiang1__yuzhongbro"))
    if #mark == 0 then return end
    local to = room:getPlayerById(mark[1][1])
    room:changeMaxHp( to , 1)
    if to.maxHp - to.hp > 0 then
      room:recover{
        who = to,
        num = to.maxHp - to.hp,
        recoverBy = player,
        skillName = "hx__nijing_bro",
      }
    end
  end,
}


local hx__xinhun_bro = fk.CreateViewAsSkill{
  name = "hx__xinhun_bro",
  pattern = "peach,slash,jink,nullification",
  card_filter = function(self, to_select, selected)
    if #selected == 2 then
      return false
    elseif #selected == 1 then
      return Fk:getCardById(to_select):compareSuitWith(Fk:getCardById(selected[1]))
    else
      local suit = Fk:getCardById(to_select).suit
      local c
      if suit == Card.Heart then
        c = Fk:cloneCard("peach")
      elseif suit == Card.Diamond then
        c = Fk:cloneCard("fire__slash")
      elseif suit == Card.Club then
        c = Fk:cloneCard("jink")
      elseif suit == Card.Spade then
        c = Fk:cloneCard("nullification")
      else
        return false
      end
      return (Fk.currentResponsePattern == nil and c.skill:canUse(Self, c)) or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(c))
    end
  end,
  view_as = function(self, cards)
    if #cards == 0 or #cards > 2 then
      return nil
    end
    local suit = Fk:getCardById(cards[1]).suit
    local c
    if suit == Card.Heart then
      c = Fk:cloneCard("peach")
    elseif suit == Card.Diamond then
      c = Fk:cloneCard("fire__slash")
    elseif suit == Card.Club then
      c = Fk:cloneCard("jink")
    elseif suit == Card.Spade then
      c = Fk:cloneCard("nullification")
    else
      return nil
    end
    c.skillName = self.name
    c:addSubcards(cards)
    return c
  end,
  before_use = function(self, player, use)
    local num = #use.card.subcards
    if num == 2 then
      local suit = Fk:getCardById(use.card.subcards[1]).suit
      if suit == Card.Diamond then
        use.additionalDamage = (use.additionalDamage or 0) + 1 + player:getMark("@huixiang1__yuzhongbro")
        player:drawCards(1 + player:getMark("@huixiang1__yuzhongbro"), self.name)
      elseif suit == Card.Heart then
        use.additionalRecover = (use.additionalRecover or 0) + 1 + player:getMark("@huixiang1__yuzhongbro")
        player:drawCards(1 + player:getMark("@huixiang1__yuzhongbro"), self.name)
      end
    end
  end,
}
local hx__xinhun_bro_obtaincard = fk.CreateTriggerSkill{
  name = "#hx__xinhun_bro_delay",
  events = {fk.CardUseFinished},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and table.contains(data.card.skillNames, "hx__xinhun_bro") and #data.card.subcards == 2 and Fk:getCardById(data.card.subcards[1]).color == Card.Black and not player.dead
  end,
  on_cost = function() return true end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local from = room.current
      if from and not from.dead and not from:isAllNude() then
        room:doIndicate(player.id, {from.id})
        local card = room:askForCardChosen(player, from, "hej", self.name)
        room:obtainCard(player, card, false, fk.ReasonPrey)
        if player:getMark("@huixiang1__yuzhongbro") > 0 then
          for _ = 1, player:getMark("@huixiang1__yuzhongbro") do
            if not from:isAllNude() then
              room:doIndicate(player.id, {from.id})
              local card2 = room:askForCardChosen(player, from, "hej", self.name)
              room:obtainCard(player, card2, false, fk.ReasonPrey)
            end
          end
        end
      end
  end,
}
huixiang1__yuzhongbro:addSkill(hx__qifu_bro)
hx__qifu_bro:addRelatedSkill(hx__qifu_bro_delay)

huixiang1__yuzhongbro:addSkill(hx__qice_bro)

huixiang1__yuzhongbro:addSkill(hx__xinhun_bro)
hx__xinhun_bro:addRelatedSkill(hx__xinhun_bro_obtaincard)

huixiang1__yuzhongbro:addSkill(hx__nijing_bro)
hx__nijing_bro:addRelatedSkill(hx__nijing_bro_maxcards)
hx__nijing_bro:addRelatedSkill(hx__nijing_bro_jiayi)

huixiang1__yuzhongbro:addSkill(hx__rendu_bro)


local hxgod__doro = General:new(extension, "hxgod__doro","god",3,3,General.Female)
Fk:loadTranslationTable{
  ["hxgod__doro"] = "doro",
  ["#hxgod__doro"] = "胜利女神",
  ["cv:hxgod__doro"] = "doro",
  ["designer:hxgod__doro"] = "庆思书",
  ["illustrator:hxgod__doro"] = "doro爱好者",
  ["hx__chouka"] = "抽卡",
  ["#hx__chouka_delay"] = "抽卡",
  [":hx__chouka"] = "持恒技，①此技能未对所有其他角色发动过前你不会死亡且体力值护甲及体力上限不会减少。②一名其他角色使用牌指定你为唯一目标后，你与其依次随机展示牌堆（包括弃牌堆）中的一张牌并根据这两张牌的类型、花色、点数、牌名中相同项的数量执行相应效果："..
"<br>4，该角色更改身份为与你相同然后你的身份获得游戏胜利；"..
"<br>3，该角色与你各加两点体力上限并回满体力；"..
"<br>2，该角色与你交换位置然后你执行一个额外的回合、其摸两张牌；"..
"<br>1，该角色失去体力至一点并可以令除你以外的一名角色将武将替换为随机非神势力的doro（无则替换为标刘备）；"..
"<br>0，该角色立即死亡然后中止当前事件并在另一名角色执行此效果后复活。",
  ["@hx__chouka_count"] = "已抽卡",
}


local hx__chouka = fk.CreateTriggerSkill{
  name = "hx__chouka",
  mutu = true,
  frequency = Skill.Compulsory,
  anim_type = "special",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.from ~= player.id and #AimGroup:getAllTargets(data.tos) == 1
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local from = room:getPlayerById(data.from)
    room:notifySkillInvoked(player, self.name, "special")
 --   if player:usedSkillTimes(self.name, Player.HistoryRound) == 1 then
   --   if player.room:askForSkillInvoke(player, self.name, data, "抽卡：是否播放doroの小曲？（每轮只能播放一次，另外不要重复播放哦）") then
   --     room:broadcastPlaySound("./packages/huixiang/audio/skill/doromusic")
   --   end
  --  end
    room:doIndicate(player.id, {from.id})
    room:addPlayerMark(from,"@hx__chouka_count")
    local card1 = room:getCardsFromPileByRule(".", 1,"allPiles")
    room:doBroadcastNotify("ShowToast", "doro的抽卡结果是……")
    room:delay(2000)
    player:showCards(card1)
    local card2 = room:getCardsFromPileByRule(".", 1,"allPiles")
    room:doBroadcastNotify("ShowToast", "该角色的抽卡结果是……")
    room:delay(2000)
    from:showCards(card2)
    local n = 0
    local type1 = Fk:getCardById(card1[1]).type
    local type2 = Fk:getCardById(card2[1]).type
    local suit1 = Fk:getCardById(card1[1]).suit
    local suit2 = Fk:getCardById(card2[1]).suit
    local num1 = Fk:getCardById(card1[1]).number
    local num2 = Fk:getCardById(card2[1]).number
    local name1 = Fk:getCardById(card1[1]).name
    local name2 = Fk:getCardById(card2[1]).name
    if type1 == type2 then
      n = n + 1
    end
    if suit1 == suit2 then
      n = n + 1
    end
    if num1 == num2 then
      n = n + 1
    end
    if name1 == name2 then
      n = n + 1
    end
    room:sendLog{
      type = "【抽卡】相同项的数量是%arg！！！",
      arg = n,
    }
    room:delay(1000)
    if n == 4 then
      if not from.dead then
        room:setPlayerProperty(from, "role", player.role)
      end
      room:doBroadcastNotify("ShowToast", "【抽卡】相同项的数量是4！！！！恭喜该角色更改身份为与doro相同并与doro一起获得游戏胜利！")
      if player.room:askForSkillInvoke(player, self.name, data, "抽卡：是否播放doroの小曲？") then
        room:broadcastPlaySound("./packages/huixiang/audio/skill/doromusic")
      end
      room:delay(2000)
      room:gameOver(player.role)
    elseif n == 3 then
      room:doBroadcastNotify("ShowToast", "【抽卡】相同项的数量是3！！！恭喜该角色与doro各加两点体力上限并回满体力！")
      if player.room:askForSkillInvoke(player, self.name, data, "抽卡：是否播放doroの小曲？") then
        room:broadcastPlaySound("./packages/huixiang/audio/skill/doromusic")
      end
      room:changeMaxHp(player, 2)
      room:recover({
        who = player,
        num = player:getLostHp(),
        skillName = self.name
      })
      room:changeMaxHp(from, 2)
      room:recover({
        who = from,
        num = from:getLostHp(),
        skillName = self.name
      })
    elseif n == 2 then
      room:doBroadcastNotify("ShowToast", "【抽卡】相同项的数量是2！！恭喜该角色与doro交换位置然后摸两张牌并令doro执行一个额外的回合！") 
      room:swapSeat(from, player)
      from:drawCards(2,self.name)
      player:gainAnExtraTurn(false)
    elseif n == 1 then
      room:doBroadcastNotify("ShowToast", "【抽卡】相同项的数量是1！太遗憾了该角色的体力值变成一点了。。") 
      if not from.dead then
        room:loseHp(from, from.hp - 1, self.name)
        local targets = table.filter(room:getAlivePlayers(), function (p) return p.id ~= player.id end)
        local tos = room:askForChoosePlayers(from,table.map(targets, Util.IdMapper), 1, 1, "令一名角色将武将替换为随机非神势力的doro（无则替换为标刘备）!", self.name, true)
        if #tos > 0 then
          local to = room:getPlayerById(tos[1])
          room:changeHero(to, "liubei", false, false, true)
        end
      end
    elseif n == 0 then
      room:doBroadcastNotify("ShowToast", "【抽卡】相同项的数量是0。。太遗憾了该角色死亡了，但是别担心，doro会复活你的！") 
      local to_revive = {room:getTag("hx__chouka_dead")} or {}
      room:killPlayer({who = from.id})
      if #to_revive > 0 then
        room:revivePlayer(to_revive[1], true)
      end
      room:setTag("hx__chouka_dead", from)
      room.logic:getCurrentEvent():findParent(GameEvent.Phase):shutdown()
    end
  end
}

local hx__chouka_delay = fk.CreateTriggerSkill{
  name = "#hx__chouka_delay",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.PreHpLost, fk.DamageInflicted,fk.BeforeMaxHpChanged,fk.AskForPeachesDone},
  can_trigger = function(self, event, target, player, data)
  local targets = table.filter(player.room:getOtherPlayers(player), function (p) return p:getMark("@hx__chouka_count") > 0 end)
  if #targets >= #player.room:getOtherPlayers(player) then return end
  if player:hasSkill(self) then
    return player == target and ((event == fk.DamageInflicted) or event == fk.PreHpLost or (event == fk.BeforeMaxHpChanged and data.num < 0 )
    or (event == fk.AskForPeachesDone and player.hp <= 0 and player.dying))
  end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.AskForPeachesDone then
      data.ignoreDeath = true
    end
    return true
  end,
}

hxgod__doro:addSkill(hx__chouka)
hx__chouka:addRelatedSkill(hx__chouka_delay)

hx__chouka.permanent_skill = true
hx__chouka_delay.permanent_skill = true


return extension